{% extends "erp/base.html" %}

{% block title %}物料库存{% endblock %}

{% block content %}
<div class="row">
    <div class="col-md-12">
        <h2>物料库存查询</h2>
        
        <div class="search-box">
            <form method="get" class="row g-3">
                <div class="col-md-8">
                    <input type="text" class="form-control" name="search" placeholder="输入物料SKU搜索..." value="{{ search_query }}">
                </div>
                <div class="col-md-2">
                    <button type="submit" class="btn btn-primary">搜索</button>
                </div>
                <div class="col-md-2">
                    <a href="{% url 'material_inventory' %}" class="btn btn-secondary">重置</a>
                </div>
            </form>
        </div>
        
        <div class="table-responsive">
            <table class="table table-striped table-hover">
                <thead>
                    <tr>
                        <th>SKU</th>
                        <th>当前库存</th>
                        <th>新库存</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    {% for item in inventory_data %}
                    <tr>
                        <td>{{ item.sku }}</td>
                        <td>{{ item.total_pcs }}</td>
                        <td>
                            <form method="post" action="{% url 'update_material_inventory' %}" style="display: inline;">
                                {% csrf_token %}
                                <input type="hidden" name="sku" value="{{ item.sku }}">
                                <input type="hidden" name="current_pcs" value="{{ item.total_pcs }}">
                                <input type="number" name="new_pcs" class="form-control"
                                       value="{{ item.total_pcs }}" min="0" required style="display: inline; width: auto;">
                        </td>
                        <td>
                                <button type="submit" class="btn btn-sm btn-primary">
                                    确认调整
                                </button>
                            </form>
                        </td>
                    </tr>
                    {% empty %}
                    <tr>
                        <td colspan="4" class="text-center">没有找到匹配的物料库存数据</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>
{% endblock %}